package com.chinairi.mall.controller;


import com.chinairi.common.utils.ResponseUtil;
import com.chinairi.mall.controller.viewobject.HomePicListVO;
import com.chinairi.mall.model.HomePic;
import com.chinairi.mall.model.HomePicType;
import com.chinairi.mall.service.IHomePicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.chinairi.common.controller.BaseController;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Webgasd
 * @since 2020-09-11
 */
@RestController
@RequestMapping("/home-pic")
public class HomePicController extends BaseController {
    @Autowired
    private IHomePicService iHomePicService;

    /**
     * 配置图片
     *
     * @param homePic 图片对象
     */
    @PostMapping("/config")
    @ResponseBody
    public void config(@RequestBody HomePic homePic) throws IOException {
        iHomePicService.config(homePic);
        ResponseUtil.showMessage("success", "图片添加成功", null);
    }

    /**
     * 更新图片表
     *
     * @param homePic 图片对象
     */
    @PutMapping("/update")
    @ResponseBody
    public void update(HomePic homePic) throws IOException {
        iHomePicService.update(homePic);
        ResponseUtil.showMessage("success", "图片更新成功", null);
    }

    /**
     * 删除图片
     *
     * @param uuid 主键
     */
    @DeleteMapping("/delete")
    @ResponseBody
    public void delete(String uuid) throws IOException {
        iHomePicService.delete(uuid);
        ResponseUtil.showMessage("success", "删除图片成功!", null);
    }

    /**
     * 获取所有图片
     */
    @GetMapping("/get")
    @ResponseBody
    public void getList() throws IOException {
        List<HomePic> list = iHomePicService.get();
        ResponseUtil.showMessage("success", "获取图片列表", list);
    }

    /**
     * 获取主页的广告图和四区图
     */
    @GetMapping("/getHomePic")
    @ResponseBody
    public void getHomePic() throws IOException {
        HomePicListVO homePicListVO = new HomePicListVO();
        homePicListVO = iHomePicService.getList();
        ResponseUtil.showMessage("success", "获取主页图片", homePicListVO);
    }
}
